package com.zhf.servlet.student;

import com.zhf.service.StudentService;
import com.zhf.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "StudentDeleteServlet", urlPatterns = "/studentDelete")
public class StudentDeleteServlet extends HttpServlet {
    StudentService studentService = new StudentServiceImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String[] studentIds = request.getParameterValues("studentId");
        boolean idDelete = studentService.deleteStudentList(studentIds);
        if(idDelete){
            request.setAttribute("msg", "删除成功");
            request.setAttribute("code", "100");
        }
        else{
            request.setAttribute("msg", "删除失败，员工编号已存在！");
            request.setAttribute("code", "101");
        }
        request.getRequestDispatcher("index.do").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
